package com.wut.clock.factory.number;

import com.wut.clock.common.constant.CommentConstant;
import com.wut.clock.common.util.RedisKeyUtil;
import com.wut.clock.vo.portal.ArticleCountVo;
import com.wut.clock.vo.portal.CommentCountVo;
import com.wut.clock.vo.portal.UserCountVo;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * @author ZYH
 * @unit D9Lab
 * @description 评论的点赞数和点踩数
 * @date 2022/6/13 16:16
 */
@SuppressWarnings("unchecked")
public class CommentCount implements Number{

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public CommentCountVo countCommentNumber(Integer commentId) {
        // 点赞数
        String entityLikeKey = RedisKeyUtil.getEntityLikeKey(commentId, CommentConstant.TopicType.COMMENT.getCode());
        Long likeCount = redisTemplate.opsForValue().size(entityLikeKey);
        // TODO 点踩数

        CommentCountVo commentCountVo = new CommentCountVo();
        commentCountVo.setLikeCount(likeCount==null ? 0:likeCount);
        return commentCountVo;
    }

    @Override
    public UserCountVo countUserNumber(Integer userId) {
        return null;
    }

    @Override
    public ArticleCountVo countArticleNumber(Integer articleId) {
        return null;
    }
}
